package com.ruoyi.web.controller.grape;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.grape.domain.GrapeTrends;
import com.ruoyi.grape.service.IGrapeTrendsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 庄园动态信息Controller
 * 
 * @author ld
 * @date 2023-11-18
 */
@RestController
@RequestMapping("/grape/trends")
public class GrapeTrendsController extends BaseController
{
    @Autowired
    private IGrapeTrendsService grapeTrendsService;

    /**
     * 查询庄园动态信息列表
     */
    @PreAuthorize("@ss.hasPermi('grape:trends:list')")
    @GetMapping("/list")
    public TableDataInfo list(GrapeTrends grapeTrends)
    {
        startPage();
        List<GrapeTrends> list = grapeTrendsService.selectGrapeTrendsList(grapeTrends);
        return getDataTable(list);
    }

    /**
     * 导出庄园动态信息列表
     */
    @PreAuthorize("@ss.hasPermi('grape:trends:export')")
    @Log(title = "庄园动态信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GrapeTrends grapeTrends)
    {
        List<GrapeTrends> list = grapeTrendsService.selectGrapeTrendsList(grapeTrends);
        ExcelUtil<GrapeTrends> util = new ExcelUtil<GrapeTrends>(GrapeTrends.class);
        util.exportExcel(response, list, "庄园动态信息数据");
    }

    /**
     * 获取庄园动态信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('grape:trends:query')")
    @GetMapping(value = "/{trendsId}")
    public AjaxResult getInfo(@PathVariable("trendsId") Long trendsId)
    {
        return success(grapeTrendsService.selectGrapeTrendsByTrendsId(trendsId));
    }

    /**
     * 新增庄园动态信息
     */
    @PreAuthorize("@ss.hasPermi('grape:trends:add')")
    @Log(title = "庄园动态信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GrapeTrends grapeTrends)
    {
        return toAjax(grapeTrendsService.insertGrapeTrends(grapeTrends));
    }

    /**
     * 修改庄园动态信息
     */
    @PreAuthorize("@ss.hasPermi('grape:trends:edit')")
    @Log(title = "庄园动态信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GrapeTrends grapeTrends)
    {
        return toAjax(grapeTrendsService.updateGrapeTrends(grapeTrends));
    }

    /**
     * 删除庄园动态信息
     */
    @PreAuthorize("@ss.hasPermi('grape:trends:remove')")
    @Log(title = "庄园动态信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{trendsIds}")
    public AjaxResult remove(@PathVariable Long[] trendsIds)
    {
        return toAjax(grapeTrendsService.deleteGrapeTrendsByTrendsIds(trendsIds));
    }
}
